﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="load_Chart.aspx.cs" Inherits="SQT.tracnghiem.Ajax.ASP.Accountant.load_Chart" %>

<%@ Import Namespace="DataAccess" %>
<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<body>
    <%
        int id = int.Parse(Request.QueryString["id"]);
        int month = int.Parse(Request.QueryString["month"]);
        int year = int.Parse(Request.QueryString["year"]);
        var get_staff = from p in new TblManagerController().FetchAll() orderby p.Role ascending where (p.Role != 1 && p.Active == true) select p;
        if (id != -1)
        {
            get_staff = from p in new TblManagerController().FetchAll() orderby p.Role ascending where (p.Role == id && p.Active == true) select p;
        }
        foreach (TblManager manager in get_staff)
        {
            int absent_accept = 0;
            int absent_unaccept = 0;
            int overtime = 0;
            int miss = 0;
            int enough =0;
            int late = 0;
            string late_date = "", absent_accept_date = "", absent_unaccept_date="",overtime_date="",miss_date="";
            
            int time = 0;
            var get_absent = new TblCheckManagerController().FetchAll().Where(x => x.ManagerId == manager.ManagerId && DateTime.Parse(x.CheckIn.ToString()).Month == month && DateTime.Parse(x.CheckIn.ToString()).Year == year && x.Absent == true);
            foreach (TblCheckManager chk in get_absent)
            {
                if (chk.Accept == true)
                {
                    absent_accept++;
                    absent_accept_date += DateTime.Parse(chk.CheckIn.ToString()).Day+", ";
                }
                else
                {
                    absent_unaccept++;
                    absent_unaccept_date += DateTime.Parse(chk.CheckIn.ToString()).Day + ", ";
                }
            }
            var get_overtime = new TblCheckManagerController().FetchAll().Where(x => x.ManagerId == manager.ManagerId && DateTime.Parse(x.CheckIn.ToString()).Month == month && DateTime.Parse(x.CheckIn.ToString()).Year == year && x.Accept == true);
            foreach (TblCheckManager chk in get_overtime)
            {
                if (chk.OverTime == true)
                {
                    overtime++;
                    overtime_date += DateTime.Parse(chk.CheckIn.ToString()).Day + ", ";
                }
            }
            for(int i=1;i<=31;i++)
            {
                var get_time = new TblCheckManagerController().FetchAll().Where(x => x.ManagerId == manager.ManagerId && DateTime.Parse(x.CheckIn.ToString()).Month == month && DateTime.Parse(x.CheckIn.ToString()).Year == year && DateTime.Parse(x.CheckIn.ToString()).Day == i && x.Accept == true && x.Absent == false);
                if (get_time.ToList().Count == 1)
                {
                    miss++;
                    miss_date += i + ", ";
                }
                if (get_time.ToList().Count > 1)
                    enough++;
                foreach (TblCheckManager check in get_time)
                {
                    if (check_Late(DateTime.Parse(check.CheckIn.ToString())) == true)
                    {
                        late++;
                        late_date += DateTime.Parse(check.CheckIn.ToString()).Day + ", ";
                    }
                }
                time += get_time.ToList().Count;
            }
    %>
    <div class="w3-border-bottom">
        <div class="chart_staff_id w3-hide"><%=manager.ManagerId %></div>
        <div class="chart_staff_name w3-hide"><%=manager.FullName %></div>
        <canvas class="canvas"></canvas>
        <div class="w3-row w3-padding w3-center">
            <span class="w3-border-bottom w3-border-teal">Đủ ca:</span>&nbsp;<label><%=enough %></label>&nbsp;|&nbsp;
                            <span <%if (miss_date != ""){ %>data-toggle="tooltip" data-placement="bottom" title="Ngày: <%=miss_date %>"<%} %> class="w3-border-bottom w3-border-teal">Thiếu ca:</span>&nbsp;<label><%=miss %></label>&nbsp;|&nbsp;
                            <span <%if (overtime_date != ""){ %>data-toggle="tooltip" data-placement="bottom" title="Ngày: <%=overtime_date %>"<%} %> class="w3-border-bottom w3-border-teal">Tăng ca:</span>&nbsp;<label><%=overtime %></label>&nbsp;|&nbsp;
                            <span <%if(absent_accept_date!=""){ %>data-toggle="tooltip" data-placement="bottom" title="Ngày: <%=absent_accept_date %>"<%} %> class="w3-border-bottom w3-border-teal">Vắng có phép:</span>&nbsp;<label><%=absent_accept %></label>&nbsp;|&nbsp;
                            <span <%if(absent_unaccept_date!=""){ %>data-toggle="tooltip" data-placement="bottom" title="Ngày: <%=absent_unaccept_date %>"<%} %> class="w3-border-bottom w3-border-teal">Vắng không phép:</span>&nbsp;<label><%=absent_unaccept %></label>&nbsp;
            <span <%if(late_date!=""){ %>data-toggle="tooltip" data-placement="bottom" title="Ngày: <%=late_date %>"<%} %> class="w3-border-bottom w3-border-teal">Số ca đi trễ:</span>&nbsp;<label><%=late %>/<%=time %></label>
        </div>
    </div>
    <%} %>
</body>
</html>
